package examples.codequality.app;

import examples.codequality.domain.User;
import examples.codequality.domain.UserGateway;
import jakarta.annotation.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.async.DeferredResult;

import java.util.UUID;

/**
 * @author baigod
 */
@Component
public class UserCreateCmdExe {

    @Resource
    UserGateway userGateway;

    public void execute(String username, DeferredResult<ResponseEntity<User>> response) {

        User user = User.builder()
                .id(UUID.randomUUID())
                .username(username)
                .build();

        userGateway.create(user);

        response.setResult(ResponseEntity.ok(user));
    }
}